package operation.impl;

import book.Book;
import book.BookList;
import operation.IOperation;

import java.util.Scanner;

/**
 * 借阅图书
 */
public class BorrowOperation implements IOperation {

    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书");
        System.out.println("请输入要借阅的图书：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        for(int i = 0; i < bookList.getUsedSize(); i++){
            Book book = bookList.getBook(i);
            if(name.equals(book.getName())){
                if(book.isBorrowed()){
                    System.out.println("不好意思，您要借的书已经借出去了。");
                    return;
                }
                book.setBorrowed(true);
                System.out.println("恭喜您借书成功！");
                return;
            }
        }
        System.out.println("不好意思，没有找到您要借阅的图书。");
    }
}
